package com.yl.applicationsecurity.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yl.applicationsecurity.mapper.SgmSafeRiskItemMapper;
import com.yl.applicationsecurity.mapper.SgmSafeRiskMapper;
import com.yl.applicationsecurity.pojo.SgmSafeRisk;
import com.yl.applicationsecurity.pojo.SgmSafeRiskItem;
import com.yl.applicationsecurity.service.SgmSafeRiskItemService;
import com.yl.applicationsecurity.service.SgmSafeRiskService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 鹤仙问鹿仙
 * @program: Application-security
 * @description:
 * @date 2025-02-08 18:11:48
 */
@Service
public class SgmSafeRiskItemServiceImpl extends ServiceImpl<SgmSafeRiskItemMapper, SgmSafeRiskItem> implements SgmSafeRiskItemService {
    @Override
    public SgmSafeRiskItem findSafeRiskItemBySgmSafeRisk(Long safeRiskId) {


        LambdaQueryWrapper<SgmSafeRiskItem> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SgmSafeRiskItem::getSafeRiskId,safeRiskId).orderByDesc(SgmSafeRiskItem::getSyncTime).last("LIMIT 1") .select(SgmSafeRiskItem::getSafeRiskId, SgmSafeRiskItem::getQueryString,SgmSafeRiskItem::getResponse);


        return baseMapper.selectOne(lambdaQueryWrapper);

    }

    @Override
    public List<SgmSafeRiskItem> findListBySafeRiskId(Long safeRiskId) {
        LambdaQueryWrapper<SgmSafeRiskItem> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SgmSafeRiskItem::getSafeRiskId,safeRiskId).orderByDesc(SgmSafeRiskItem::getCreateTime).select(SgmSafeRiskItem::getId,SgmSafeRiskItem::getSafeRiskId, SgmSafeRiskItem::getQueryString,SgmSafeRiskItem::getResponse,SgmSafeRiskItem::getCreateTime);
        return baseMapper.selectList(lambdaQueryWrapper);
    }
}

